var config = {
    rootPath: 'D:\\springProject\\demo\\demo-ui',
    baseUrl: 'http://192.168.1.100:8080',
    jsEvent: {},
    getParamStr: function (jsonParams) {
        return {paramStr: JSON.stringify(jsonParams)};
    },
    call: function (params) {
        if(!params && !params.url){
            return;
        }
        var url = params.url;
        var data = params.data || {};
        var beforeSend = params.beforeSend;
        var success = params.success;
        var complete = params.complete;
        var error = params.error;
        var type = params.type?params.type:'POST';
        var async = params.async != undefined ? params.async:true;
        //var dataType = params.dataType?params.dataType:

        var cookies = document.cookie;
        if(cookies){
            var cookiesArr = cookies.split(';');
            for(var i=0;i<cookiesArr.length;i++){
                var cookieArr = cookiesArr[i].split('=');
                var name = cookieArr[0].trim();
                if(name == 'token'){
                    var value = cookieArr[1].trim();
                    data['token'] = value;
                }
            }
        }

        $.ajax({
            url: url,
            data:data,
            type: type,
            async: async,
            beforeSend: function () {
                lightyear.loading('show');

                if(beforeSend && typeof beforeSend == "function"){
                    beforeSend();
                }

            },
            success: function (result) {
                if(result && !result.success && result.code == 448){
                    alert(result.msg);
                    window.location.href = '../../login/login.html';
                    return;
                }

                if(success && typeof success == "function"){
                    success(result);
                }
            },
            complete: function () {
                lightyear.loading('hide');

                if(complete && typeof complete == "function"){
                    complete();
                }
            },
            error: function (result) {
                lightyear.loading('hide');

                if(error && typeof error == "function"){
                    error();
                }
            }
        });
    },
    getQueryVariable: function (variable) {
        var query = window.location.search.substring(1);
        var vars = query.split("&");
        for (var i=0;i<vars.length;i++) {
            var pair = vars[i].split("=");
            if(pair[0] == variable){return pair[1];}
        }
        return(false);
    },
    loadHtml: function (path) {
        var html = '';
        config.call({
            url: config.baseUrl+'/sysConfig/loadHtml',
            data:{path: config.rootPath + path},
            type: 'POST',
            async: false,
            beforeSend: function () {

            },
            success: function (result) {
                if(result && result.success){
                    html = result.data.html;
                }

            },
            complete: function () {

            },
            error: function (result) {

            }
        });

        return html;
    },
    initNav: function ($a) {
        var selectNavPath = $a.attr('data-url');
        if(selectNavPath){
            var html = config.loadHtml(selectNavPath);
            $('.container-fluid').find('.row').html(html);
        }

        var jsModel = $a.attr('data-jsModel');
        if(jsModel){
            var jsPath = '\\js\\page\\'+jsModel+'.js';
            var jsCode = config.loadHtml(jsPath);
            config.jsEvent[jsModel] = eval(jsCode);

            console.log(config.jsEvent)

            //config.jsEvent[jsModel].initData();
        }
    }
}